package com.example.prison.mapper;

import com.example.prison.entity.PushRecord;
import com.example.prison.entity.PushRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author jiang
* @description 针对表【push_record】的数据库操作Mapper
* @createDate 2023-06-13 09:32:29
* @Entity com.example.prison.entity.PushRecord
*/
@Mapper
public interface PushRecordMapper extends BaseMapper<PushRecord> {

    @Select("<script>select * from push_record " +
            " <where> " +
            " <if test=\"alarmLevel != null and alarmLevel != ''\">and alarm_level like concat('%',#{alarmLevel},'%') </if> " +
            " <if test=\"beginTime != null and beginTime != ''\">and push_time &gt;= #{beginTime} </if> " +
            " <if test=\"endTime != null and endTime != ''\">and push_time &lt;= #{endTime} </if> " +
            " <if test=\"pushPersonnel != null and pushPersonnel != ''\">and push_personnel like concat('%',#{pushPersonnel},'%') </if> " +
            " </where> " +
            "order by id desc</script>")
    List<PushRecord> get(@Param("alarmLevel") String alarmLevel, @Param("pushPersonnel") String pushPersonnel,
                         @Param("beginTime") String beginTime, @Param("endTime") String endTime);

    @Insert("insert into push_record(alarm_level, push_personnel, note, push_time) " +
            "values (#{alarmLevel}, #{pushPersonnel}, #{note}, #{pushTime})")
    int add(PushRecord record);

    @Select("select * from push_record where id = #{id}")
    PushRecord getById(@Param("id") Integer id);

}




